package com.xiaode.controller.app.myCampus.happy;

import com.jfinal.aop.Inject;
import com.jfinal.core.Controller;
import com.jfinal.core.Path;
import com.jfinal.ext.cors.EnableCORS;
import com.jfinal.kit.Ret;
import com.xiaode.common.anotation.JSONArrayString;
import com.xiaode.util.apidoc.annotation.Api;
import com.xiaode.util.apidoc.annotation.ApiOper;
import com.xiaode.util.apidoc.annotation.ApiPara;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.Size;

@Path("/happy")
@Api("乐学园相关服务")
@EnableCORS
public class HappyCurriculumController extends Controller {
	
    @Inject
    HappyCurriculumService service;
    
    
    /**
     * 获取课程类型
     */
    @ApiOper("获取课程类型")
    public void getCurriculumMod() throws Exception{
    	Ret ret = service.getCurriculumMod();
    	renderJson(ret);
    }
    
    /**
     * 获取更多课程
     */
    @ApiOper("获取更多课程")
    public void getCurriculumModAll() throws Exception{
    	Ret ret = service.getCurriculumModAll();
    	renderJson(ret);
    }
    
    /**
     * 获取对应课程分类的子类
     */
    @ApiOper("获取对应课程分类的子类")
    public void getCurriculumModSon(@NotEmpty @Size(min = 0) @ApiPara(value = "curriculumModId", notes = "分类id") Integer curriculumModId) throws Exception{
    	Ret ret = service.getCurriculumModSon(curriculumModId);
    	renderJson(ret);
    }

    /**
     * 获取推荐的课程
     */
    @ApiOper("获取推荐的课程")
    public void getRecommend() throws Exception{
    	Ret ret = service.getRecommend();
    	renderJson(ret);
    }
    
    /**
     * 获取老师发布的课程
     */
    @ApiOper("获取老师发布的课程")
    public void getTeacherPublicCurriculum(
    		@Size(min = 0) @ApiPara(value = "publisherId", notes = "发布人id") Integer publisherId,
    		@NotEmpty @Size(min = 0) @ApiPara(value = "page", notes = "当前页") Integer page,
    		@NotEmpty @Size(min = 0) @ApiPara(value = "limit", notes = "每页大小") Integer limit) throws Exception{
    	Ret ret = service.getTeacherPublicCurriculum(publisherId, page, limit);
    	renderJson(ret);
    }
    
    /**
     * 获取最近跟新的课程
     */
    @ApiOper("获取最近更新的课程")
    public void getNewUpdateCurriculum(
    		@NotEmpty @Size(min = 0) @ApiPara(value = "page", notes = "当前页") Integer page,
    		@NotEmpty @Size(min = 0) @ApiPara(value = "limit", notes = "每页大小") Integer limit) throws Exception{
    	Ret ret = service.getNewUpdateCurriculum(page, limit);
    	renderJson(ret);
    }
    
    /**
     * 分页获取某个课程类下的课程
     */
    @ApiOper("分页获取某个课程类下的课程")
    public void getCurriculumByMod(
    		@NotEmpty @Size(min = 0) @ApiPara(value = "modId", notes = "分类id") Integer modId,
    		@NotEmpty @Size(min = 0) @ApiPara(value = "page", notes = "当前页") Integer page,
    		@NotEmpty @Size(min = 0) @ApiPara(value = "limit", notes = "每页大小") Integer limit) throws Exception{
    	Ret ret = service.getCurriculumByMod(modId, page, limit);
    	renderJson(ret);
    }
    
    /**
     * 课程详情
     */
    @ApiOper("课程详情")
    public void getCurriculumInfo(@NotEmpty @Size(min = 0) @ApiPara(value = "curriculumId", notes = "课程Id") Integer curriculumId) throws Exception{
    	Integer userId = getAttr("userId");
    	Integer userType = getAttr("userType");
    	Ret ret = service.getCurriculumInfo(userId, userType, curriculumId);
    	renderJson(ret);
    }
    
    /**
     * 获取课程大纲
     */
    @ApiOper("获取课程大纲")
    public void getChapterDivision(@NotEmpty @Size(min = 0) @ApiPara(value = "curriculumId", notes = "课程Id") Integer curriculumId) throws Exception{
    	Ret ret = service.getChapterDivision(curriculumId);
    	renderJson(ret);
    }
    
    /**
     * 我学习过的课程（只要进入过课程的就算）
     */
    @ApiOper("我学习过的课程（只要进入过课程的就算）")
    public void getMyCurriculum(
    		@Size(min = 0) @ApiPara(value = "studentId", notes = "学生id") Integer studentId,
    		@NotEmpty @Size(min = 0) @ApiPara(value = "page", notes = "当前页") Integer page,
    		@NotEmpty @Size(min = 0) @ApiPara(value = "limit", notes = "每页大小") Integer limit) throws Exception{
    	Integer userId = getAttr("userId");
    	Ret ret = service.getMyCurriculum(userId, studentId, page, limit);
    	renderJson(ret);
    }
    
    /**
     * 获取我观看的视频记录(顺便记录观看次数)
     */
    @ApiOper("获取我观看的视频记录(顺便记录观看次数)")
    public void getVideoRate(@NotEmpty @Size(min = 0) @ApiPara(value = "curriculumId", notes = "课程Id") Integer divisionFileId) throws Exception{
    	Integer userId = getAttr("userId");
    	Integer userType = getAttr("userType");
    	Ret ret = service.getVideoRate(userId, userType, divisionFileId);
    	renderJson(ret);
    }
    
    /**
     * 获取精彩评论
     */
    @ApiOper("获取精彩评论(前10)")
    public void getGoodComment() throws Exception{
    	Ret ret = service.getGoodComment();
    	renderJson(ret);
    }
    
    /**
     * 获取评论
     */
    @ApiOper("获取评论")
    public void getComment(
    		@NotEmpty @Size(min = 0) @ApiPara(value = "curriculumId", notes = "课程Id") Integer curriculumId,
    		@NotEmpty @Size(min = 0) @ApiPara(value = "page", notes = "当前页") Integer page,
    		@NotEmpty @Size(min = 0) @ApiPara(value = "limit", notes = "每页大小") Integer limit) throws Exception{
    	Integer accountIdMy = getAttr("accountId");
    	Ret ret = service.getComment(accountIdMy, curriculumId, page, limit);
    	renderJson(ret);
    }
    
    /**
     * 进行评论
     */
    @ApiOper("进行评论")
    public void createComment(
    		@NotEmpty @Size(min = 0) @ApiPara(value = "curriculumId", notes = "课程Id") Integer curriculumId,
            @NotBlank @Size(min = 1,max = 500) @ApiPara(value = "comment", notes = "评论内容") String comment,
            @Size(min = 0) @ApiPara(value = "commentsId", notes = "评论Id") Integer commentsId,
            @Size(min = 0) @ApiPara(value = "topCommentsId", notes = "顶层评论Id") Integer topCommentsId) throws Exception{
    	Integer accountId = getAttr("accountId");
    	Integer userType = getAttr("userType");
    	Ret ret = service.createComment(accountId, userType, curriculumId, comment, commentsId, topCommentsId);
    	renderJson(ret);
    }
    
    /**
     * 删除评论
     */
    @ApiOper("删除评论")
    public void deleComment(@NotEmpty @Size(min = 0) @ApiPara(value = "commentId", notes = "评论Id") Integer commentId) throws Exception{
    	Integer accountId = getAttr("accountId");
    	Ret ret = service.deleComment(accountId, commentId);
    	renderJson(ret);
    }
    
    /**
     * 点赞评论
     */
    @ApiOper("点赞评论")
    public void praiseComment(@NotEmpty @Size(min = 0) @ApiPara(value = "commentId", notes = "评论Id") Integer commentId) throws Exception{
    	Integer accountId = getAttr("accountId");
    	Ret ret = service.praiseComment(accountId, commentId);
    	renderJson(ret);
    }
    
    
    
    
    
    
    
    
    
    /**
     * 老师创建课程
     */
    @ApiOper("老师创建课程")
    public void createCurriculum(
    		@NotEmpty @Size(min = 0) @ApiPara(value = "modId", notes = "课程类型id") Integer modId,
    		@NotBlank @Size(min=2,max=16) @ApiPara(value = "name", notes = "课程名称") String name,
    		@NotBlank @Size(min=2,max=16) @ApiPara(value = "lecturerName", notes = "授课老师名称") String lecturerName,
    		@NotBlank @ApiPara(value = "labels", notes = "标签,隔开") String labels,
    		@NotBlank @Size(min=10,max=300) @ApiPara(value = "brief", notes = "课程简介") String brief,
    		@ApiPara(value = "picture", notes = "课程图片") String picture,
    		@NotBlank @JSONArrayString @ApiPara(value = "chapterDivision", notes = "章节JSON对象") String chapterDivision) throws Exception{
    	Integer userId = getAttr("userId");
    	Integer userType = getAttr("userType");
    	Ret ret = service.createCurriculum(userId, userType, modId, name, lecturerName, labels, brief, picture, chapterDivision);
    	renderJson(ret);
    }
    
    /**
     * 开课记录
     */
    @ApiOper("开课记录")
    public void curriculumRecord(@NotEmpty @Size(min = 0) @ApiPara(value = "curriculumId", notes = "课程id") Integer curriculumId) throws Exception{
    	Integer userId = getAttr("userId");
    	Integer userType = getAttr("userType");
    	Ret ret = service.curriculumRecord(userId, userType, curriculumId);
    	renderJson(ret);
    }
    
    /**
     * 开课记录名称列表
     */
    @ApiOper("开课记录名称列表")
    public void curriculumRecordNameList() throws Exception{
    	Integer userId = getAttr("userId");
    	Integer userType = getAttr("userType");
    	Ret ret = service.curriculumRecordNameList(userId, userType);
    	renderJson(ret);
    }
    
    
    /**
     * 添加课时
     */
    @ApiOper("添加课时")
    public void addDivision(
    		@NotEmpty @Size(min = 0) @ApiPara(value = "chapterId", notes = "章节id") Integer chapterId,
    		@NotBlank @Size(min=2,max=16) @ApiPara(value = "name", notes = "课时名称") String name) throws Exception{
    	Integer userId = getAttr("userId");
    	Integer userType = getAttr("userType");
    	Ret ret = service.addDivision(userId, userType, chapterId, name);
    	renderJson(ret);
    }
    
    /**
     * 添加章节
     */
    @ApiOper("添加章节")
    public void addChapter(
    		@NotEmpty @Size(min = 0) @ApiPara(value = "curriculumId", notes = "课程id") Integer curriculumId,
    		@NotBlank @Size(min=2,max=16) @ApiPara(value = "name", notes = "课时名称") String name) throws Exception{
    	Integer userId = getAttr("userId");
    	Integer userType = getAttr("userType");
    	Ret ret = service.addChapter(userId, userType, curriculumId, name);
    	renderJson(ret);
    }
    
    /**
     * 课时中添加文件
     */
    @ApiOper("课时中添加文件")
    public void addDivisionFile(@NotBlank @JSONArrayString @ApiPara(value = "divisionFileStr", notes = "文件JSON数组") String divisionFileStr) throws Exception{
    	Integer userId = getAttr("userId");
    	Integer userType = getAttr("userType");
    	Ret ret = service.addDivisionFile(userId, userType, divisionFileStr);
    	renderJson(ret);
    }
    
    /**
     * 添加章节和文件
     */
    @ApiOper("添加章节和文件")
    public void addChapterDivisionFile(
    		@NotEmpty @Size(min = 0) @ApiPara(value = "curriculumId", notes = "课程id") Integer curriculumId,
    		@NotBlank @JSONArrayString @ApiPara(value = "chapterDivisionFile", notes = "章节JSON对象(包含文件)") String chapterDivisionFile) throws Exception{
    	Integer userId = getAttr("userId");
    	Integer userType = getAttr("userType");
    	Ret ret = service.addChapterDivisionFile(userId, userType, curriculumId, chapterDivisionFile);
    	renderJson(ret);
    }
    
    /**
     * 删除课程
     */
    @ApiOper("删除课程")
    public void deleCurriculum(@NotEmpty @Size(min = 0) @ApiPara(value = "curriculumId", notes = "课程id") Integer curriculumId) throws Exception{
    	Integer userId = getAttr("userId");
    	Integer userType = getAttr("userType");
    	Ret ret = service.deleCurriculum(userId, userType, curriculumId);
    	renderJson(ret);
    }
    
    /**
     * 删除章
     */
    @ApiOper("删除章")
    public void deleChapter(@NotEmpty @Size(min = 0) @ApiPara(value = "chapterId", notes = "章id") Integer chapterId) throws Exception{
    	Integer userId = getAttr("userId");
    	Integer userType = getAttr("userType");
    	Ret ret = service.deleChapter(userId, userType, chapterId);
    	renderJson(ret);
    }
    
    /**
     * 删除课时
     */
    @ApiOper("删除课时")
    public void deleDivision(@NotEmpty @Size(min = 0) @ApiPara(value = "divisionId", notes = "课时id") Integer divisionId) throws Exception{
    	Integer userId = getAttr("userId");
    	Integer userType = getAttr("userType");
    	Ret ret = service.deleDivision(userId, userType, divisionId);
    	renderJson(ret);
    }
    
    /**
     * 删除课时文件
     */
    @ApiOper("删除课时文件")
    public void deleDivisionFile(@NotEmpty @Size(min = 0) @ApiPara(value = "divisionFileId", notes = "文件id") Integer divisionFileId) throws Exception{
    	Integer userId = getAttr("userId");
    	Integer userType = getAttr("userType");
    	Ret ret = service.deleDivisionFile(userId, userType, divisionFileId);
    	renderJson(ret);
    }
    
    
    
    
    
    
    
    
    /**
     * 保存视频观看进度
     */
    @ApiOper("保存视频观看进度")
    public void recordUserViewRate(
    		@NotEmpty @Size(min = 0) @ApiPara(value = "divisionFileId", notes = "文件id") Integer divisionFileId,
    		@NotEmpty @Size(min = 0) @ApiPara(value = "rate", notes = "进度(单位秒)") Integer rate) {
    	Integer userId = getAttr("userId");
    	Integer userType = getAttr("userType");
    	Ret ret = service.recordUserViewRate(userId, userType, divisionFileId, rate);
    	renderJson(ret);
    }
    
    /**
     * 累计学生学习总时间（暂时没有好的方案，先不做）
     */
    
    
}
